<template>
  <div class="search">
    <Row>
      <Col>
        <Card>
          <Row class="operation">
          </Row>
          <Row>
            <Table :loading="loading" border :columns="columns" :data="data" ref="table" sortable="custom" @on-sort-change="changeSort"></Table>
          </Row>
          <Row type="flex" justify="end" class="page">
            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
          </Row>
        </Card>
      </Col>
    </Row>
    <Modal :title="modalTitle" v-model="modalVisible" :mask-closable='false' :width="700">
      <div style="font-size: 14px;padding: 5px 0;"><label>店铺名称：</label>{{detailData.shopName}}</div>
      <div style="font-size: 14px;padding: 5px 0;"><label>联系方式：</label>{{detailData.mobile}}</div>
      <div style="font-size: 14px;padding: 5px 0;"><label>支付宝账号：</label>{{detailData.alipayAccount}}</div>
      <div style="font-size: 14px;padding: 5px 0;"><label>微信账号：</label>{{detailData.wechatAccount}}</div>
      <div style="font-size: 14px;padding: 5px 0;"><label>服务类型：</label>{{detailData.className}}</div>
      <div style="font-size: 14px;padding: 5px 0;"><label>所在城市：</label>{{detailData.areaName}}</div>
      <div style="font-size: 14px;padding: 5px 0;"><label>店铺地址：</label>{{detailData.address}}</div>
      <div style="font-size: 14px;padding: 5px 0;height: 200px;">
        <label>身份证正面：</label>
        <img :src="detailData.idCardFront" alt="" style="max-height: 100%;max-width: 100%;" @click="handleView(detailData.idCardFront)" />
      </div>
      <div style="font-size: 14px;padding: 5px 0;height: 200px;">
        <label>身份证反面：</label>
        <img :src="detailData.idCardBack" alt="" style="max-height: 100%;max-width: 100%;" @click="handleView(detailData.idCardBack)" />
      </div>
    </Modal>
    
    <Modal title="查看大图" v-model="visible" class-name="fl-image-modal">
      <img :src="imgUrl" v-if="visible" style="width: 100%">
    </Modal>
  </div>
</template>

<script>
import {
  getUserListData,
} from "@/api/index";
import circleLoading from "@/views/my-components/circle-loading.vue";
import uploadPicInput from "@/views/my-components/xboot/upload-pic-input.vue"
export default {
  name: "staffManagement",
  components: {
    circleLoading,
    uploadPicInput
  },
  data() {
    return {
      imgUrl: "",
      visible: false,
      loading: true, // 表单加载状态
      loadingEdit: false,
      modalType: 0, // 添加或编辑标识
      modalVisible: false, // 添加或编辑显示
      modalTitle: "", // 添加或编辑标题
      searchForm: { // 搜索框初始化对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
      },
      userform:{
       pageNumber:1,
       pageSize:10,
      },
      submitLoading: false, // 添加或编辑提交状态
      columns: [
        // 表头
        {
          type: "index",
          width: 60,
          align: "center"
        },
        {
          title: "店铺头像",
          key: "avatar",
          minWidth: 120,
          sortable: false,
          render: (h, params) => {
            return h("avatar", {
              props: {
                src: params.row.avatar
              }
            });
          }
        },
        {
          title: "店铺名称",
          key: "shopName",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "联系方式",
          key: "mobile",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "服务类型",
          key: "className",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "城市",
          key: "areaName",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "创建时间",
          key: "createTime",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          fixed: "right",
          minWidth: 200,
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small",
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.detail(params.row);
                    }
                  }
                },
                "详情"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small",
                  },
                  style: {
                    marginRight: "5px",
                    display:(params.row.status==-1)?"none":"inline-block"
                  },
                  on: {
                    click: () => {
                      this.frozen(params.row,1);
                    }
                  }
                },
                "冻结"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "default",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px",
                    display:(params.row.status==0)?"none":"inline-block"
                  },
                  on: {
                    click: () => {
                      this.frozen(params.row,2);
                    }
                  }
                },
                "解冻"
              ),
              // h(
              //   "Button",
              //   {
              //     props: {
              //       type: "primary",
              //       size: "small"
              //     },
              //     style: {
              //       marginRight: "5px"
              //     },
              //     on: {
              //       click: () => {
              //         this.message(params.row);
              //       }
              //     }
              //   },
              //   "短信"
              // ),
              // h(
              //   "Button",
              //   {
              //     props: {
              //       type: "info",
              //       size: "small"
              //     },
              //     style: {
              //       marginRight: "5px"
              //     },
              //     on: {
              //       click: () => {
              //         this.pushData(params.row);
              //       }
              //     }
              //   },
              //   "推送"
              // ),
            ]);
          }
        }
      ],
      data: [], // 表单数据
      detailData: {},
      total: 0 // 表单数据总数
    };
  },
  methods: {
    init() {
      this.getDataList();
    },
    //获取用户列表
    userSearch(){
      this.postRequest("/user/getUserList",this.userform).then(res =>{
        console.log(res)
        if(res.success){
          this.data = res.result.data
        } else {
          this.$Message.success("暂无数据");
        }
      })
    },
    handleView(url) {
      this.imgUrl = url;
      this.visible = true;
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    handleReset() {
      this.$refs.searchForm.resetFields();
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      // 重新加载数据
      this.getDataList();
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order === "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    getDataList() {
      this.loading = true;
      // 带多条件搜索参数获取表单数据 请自行修改接口
      this.postRequest("/user/getBackUserPersonStoreList", this.searchForm).then(res => {
        this.loading = false;
        if (res.success) {
          var arr = res.result.data;
          for(let val of arr){
            for(let i in val){
              (val[i] === null) ? (val[i] = "-") : ""
            }
          }  
          this.data = res.result.data;
          this.total = res.result.size;
        } else if (res.code == 201) {
          this.data=[];
          this.total=0;
        }
      });
    },
    detail (v) {
      this.modalType = 0;
      this.modalTitle = "详情";
      var data = {
        userId: v.id,
        userTypeEnum: "PER_STORE"
      }
      this.postRequest("/user/getBackUserParticulars", data).then(res=> {
        if (res.success) {
          this.detailData = res.result;
        } else {
          this.detailData = {}
        }
      })
      this.modalVisible = true;
    },
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.submitLoading = true;
          console.log("编辑")
          this.postRequest("/user/editOwn", this.form).then(res => {
            this.submitLoading = false;
            if (res.success) {
              this.$Message.success("操作成功");
              this.getDataList();
              this.modalVisible = false;
            }
          });
        }
      });
    },
    frozen(v, k) {
      console.log(v)
      let params ={
        userId:v.id
      }
      this.postRequest("/user/freezeAccount",params).then(res =>{
        console.log(res)
        if(res.success){
          if (k===1) {
            this.$Message.success("冻结成功");
          } else {
            this.$Message.success("解冻成功");
          }
          this.getDataList();
        }
      })
    },
},
  mounted() {
    this.init();
  }
};
</script>
<style lang="less">
.search {
    .operation {
        margin-bottom: 2vh;
    }
    .select-count {
        font-size: 13px;
        font-weight: 600;  
        color: #40a9ff;
    }
    .select-clear {
        margin-left: 10px;
    }
    .page {
        margin-top: 2vh;
    }
    .drop-down {
        font-size: 13px;
        margin-left: 5px;
    }
}
</style>